package bocchi.base;

import bocchi.BocchiCore;
import bocchi.general.DataLoader;
import basemod.abstracts.CustomCard;
import bocchi.general.CardData;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.monsters.AbstractMonster;

import java.util.EnumSet;

public class BaseCustomCard extends CustomCard {
    protected enum TypeFlag {
        HITORI,
        RYO,
        NIJIKA,
        KITA,
    }

    protected CardData data;
    protected EnumSet<TypeFlag> typeFlags = EnumSet.noneOf(TypeFlag.class);

    public BaseCustomCard(String rawID) {
        this(DataLoader.getCardData(rawID));
    }

    public BaseCustomCard(CardData data) {
        super(BocchiCore.getGameID(data.ID), data.NAME, data.IMG_PATH, data.COST, data.DESCRIPTION, data.TYPE, data.COLOR, data.RARITY, data.TARGET);
        damage = baseDamage = data.DAMAGE;
        block = baseBlock = data.BLOCK;
        magicNumber = baseMagicNumber = data.MAGIC_NUMBER;
        this.data = data;

        if (this.getClass() == BaseCustomCard.class) {
            name += "*";
        }
    }

    public void setType(TypeFlag type) {
        typeFlags.add(type);
    }

    public boolean isType(TypeFlag type) {
        return typeFlags.contains(type);
    }

    public void upgradeDamage() {
        int diff = data.UPGRADE_DAMAGE - data.DAMAGE;
        if (diff != 0) {
            upgradeDamage(diff);
        }
    }

    public void upgradeBlock() {
        int diff = data.UPGRADE_BLOCK - data.BLOCK;
        if (diff != 0) {
            upgradeBlock(diff);
        }
    }

    public void upgradeMagicNumber() {
        int diff = data.UPGRADE_MAGIC_NUMBER - data.MAGIC_NUMBER;
        if (diff != 0) {
            upgradeMagicNumber(diff);
        }
    }

    public void upgradeCost() {
        if (data.UPGRADE_COST != data.COST) {
            upgradeBaseCost(data.UPGRADE_COST);
        }
    }

    public void upgradeDescription() {
        if (data.UPGRADE_DESCRIPTION != null) {
            rawDescription = data.UPGRADE_DESCRIPTION;
            initializeDescription();
        }
    }

    @Override
    public void upgrade() {
        if (!upgraded) {
            upgradeName();
            upgradeDamage();
            upgradeBlock();
            upgradeMagicNumber();
            upgradeCost();
            upgradeDescription();
        }
    }

    @Override
    public void use(AbstractPlayer player, AbstractMonster monster) {}

    @Override
    public AbstractCard makeCopy() {
        if (this.getClass() == BaseCustomCard.class) {
            return new BaseCustomCard(data);
        }

        return super.makeCopy();
    }
}
